<?
if (!defined('SMF'))
	die('Hacking attempt...');

global $smcFunc, $txt, $scripturl, $settings, $user_info;
global $dbtables, $sector_max;
global $debug;

// Verify user login, if CheckLogin() returns false return to the calling script/function
if (CheckLogin() == false)
	return;

BigTitle($txt['bnt_map_title']);

//-------------------------------------------------------------------------------------------------

// Pull player info into $playerinfo.
$result = $smcFunc['db_query']('', '
	SELECT *
	FROM {raw:db_ships}
	WHERE user_id = {int:user_id}
	LIMIT 1',
	array(
		'db_ships' => $dbtables['ships'],
		'user_id' => $user_info['id'],
	)
);
$playerinfo = $smcFunc['db_fetch_assoc']($result);
$smcFunc['db_free_result']($result);

$tile['special'] = 'space261_md_blk.gif';
$tile['ore'] = 'space262_md_blk.gif';
$tile['organics'] = 'space263_md_blk.gif';
$tile['energy'] = 'space264_md_blk.gif';
$tile['goods'] = 'space265_md_blk.gif';
$tile['none'] = 'space.gif';
$tile['Unknown'] = 'uspace.gif';

$cur_sector = 0;

$result = $smcFunc['db_query']('', '
	SELECT distinct {raw:db_movement_log}.sector_id, port_type
	FROM {raw:db_movement_log}, {raw:db_universe}
	WHERE ship_id = {int:ship_id}
	AND {raw:db_movement_log}.sector_id = {raw:db_universe}.sector_id
	ORDER BY sector_id ASC',
	array(
		'db_movement_log' => $dbtables['movement_log'],
		'db_universe' => $dbtables['universe'],
		'ship_id' => $playerinfo['ship_id']
	)
);

$row = $smcFunc['db_fetch_assoc']($result);

TextMainMenu();

echo '
		<input id="current_sector" type="hidden" value="', $playerinfo['sector'], '" />
		<img src="', $settings['images_url'], '/bnt/', $tile['special'], '"> - Special Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['ore'], '"> - Ore Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['organics'], '"> - Organics Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['energy'], '"> - Energy Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['goods'], '"> - Goods Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['none'], '"> - No Port<br><br>
		<img src="', $settings['images_url'], '/bnt/', $tile['Unknown'], '"> - Unexplored<br><br>
		<table border="0" cellpadding="0">';

while ($cur_sector < $sector_max)
{
	$break = ($cur_sector + 1) % 50;
	
	if ($break == 1)
	{
	   echo '
			<tr>
				<td>', $cur_sector, '</td> ';
	}
	 
	if ($row['sector_id'] == $cur_sector)
	{         
		$port = $row['port_type'];
		$alt = $row['sector_id'] . ' - ' . $row['port_type'];
		$row = $smcFunc['db_fetch_assoc']($result);
	}
	else
	{
		$port = $txt['bnt_unknown']	;
		$alt = $cur_sector . ' - ' . $txt['bnt_unknown'];
	}
           
	echo '
				<td class="galaxy_link" title="', $alt, '">
					<img src="', $settings['images_url'], '/bnt/', $tile[$port], '" alt="', $alt, '" border="0" />
					<input type="hidden" value="', $cur_sector, '" />
				</td>';

	if ($break == 0)
	{
		echo '
				<td>', $cur_sector, '</td>
			</tr>';
    }
	
	$cur_sector = $cur_sector + 1;
}

$smcFunc['db_free_result']($result);

echo '
		</table>
		<br><br>
		<img src="', $settings['images_url'], '/bnt/', $tile['special'], '"> - Special Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['ore'], '"> - Ore Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['organics'], '"> - Organics Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['energy'], '"> - Energy Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['goods'], '"> - Goods Port<br>
		<img src="', $settings['images_url'], '/bnt/', $tile['none'], '"> - No Port<br><br>
		<img src="', $settings['images_url'], '/bnt/', $tile['Unknown'], '"> - Unexplored<br><br>';

TextMainMenu();
?> 


